package at.fhj.itm11.forum.gui;

import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import at.fhj.itm11.forum.api.ApiLookupNames;
import at.fhj.itm11.forum.service.TestHelperService;

public class US03 extends AbstractGUITest{
  private TestHelperService dbHelper;

  public void emptyDB(){
		dbHelper = lookupBean(ApiLookupNames.TEST_HELPER,
				TestHelperService.class);

		dbHelper.cleanDB();
		
		navigateToBasePage();
  }
  
  public void testDB(){
		dbHelper = lookupBean(ApiLookupNames.TEST_HELPER,
				TestHelperService.class);

		dbHelper.cleanDB();
		dbHelper.createDemoData();
		
		navigateToBasePage();
}

  //@Test
   public void happyPathTestWithoutTopic(){
	  emptyDB();  
    
	  //test as WebElement with xPath
    	WebElement title = driver.findElement(By.xpath("/html/body/div/div/aside/div/div/span"));
    	Assert.assertEquals("title do match!", "THEMEN",title.getText());
    
    	//test as WebDriver with findElement
    	assertEquals("titles do match!", "THEMEN", driver.findElement(By.cssSelector("span.nav-header")).getText());
  }
  
  @Test
  public void happyPathTestWithTopic() throws Exception {
	  testDB();
	  
	  //test as webDriver with findElement
    	assertEquals("THEMEN\nDemoThema", driver.findElement(By.id("topics")).getText());
    
    	//test as WebElement with xpath
    	WebElement title = driver.findElement(By.xpath("/html/body/div/div/aside/div/div/table/tbody/tr/td/form/li"));
    	Assert.assertEquals("topics do match!", "DemoThema",title.getText());
  }  

}